package com.krystal.mapper;

/**
 * @author Krystal1
 * @date 2021/4/26 -13:40
 */

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component
public interface CovidMapper {

    /**
     * 查询数据库表covid19_0的数据量
     * */
    @Select("select count(*) from `bigdata`.covid19_0")
    int selectDataChinaDay();

    /**
     * 查询数据库表covid19_0，返回最近一个月的境外输入的数据
     * */
    @Select("select date as `date`,importedCase as `累计境外输入` from `bigdata`.covid19_0  limit ${dataFirst},18446744073709551615")
    List<Map<String, Object>> getChinaDayImport(int dataFirst);

    /**
     * 查询当前数据库(covid19_1)的数据量
     * */
    @Select("select count(*) FROM `bigdata`.covid19_1;")
    int getDataCount();

    /**
     * 查询数据库中最后一条数据 就是最新的数据  因为数据库中的时间是id类型 不能用datetime来匹配查询
     * */
    @Select("select * from `bigdata`.covid19_1 order by id DESC limit 1")
    List<Map<String,Object>> getNationalData();

    /**
     * covid_1 表已经不用了 查疫情总览使用0表
     */
    @Select("select * from `bigdata`.covid19_0 order by id desc limit 1")
    Map<String, Object> getNationalDataNew();

    /**
    * 查询全国各省份累计确诊数据
     * 返回省份名称，累计确诊数 where datetime=#{datetime}
    **/
    @Select("select provinceShortName as name, currentConfirmedCount as value from `bigdata`.covid19_2 ")
    List<Map<String,Object>> getNationalMapData(String datetime);

    /**
     * 查询全国每一天的疫情数据
     * */
    //'dateId', '新增确诊', '累计确诊', '疑似病例', '累计治愈', '累计死亡'
    //INSERT INTO `bigdata`.`covid19_1` (`datetime`, `currentConfirmedCount`, `confirmedCount`, `suspectedCount`, `curedCount`, `deadCount`, `id`, `deadIncr`, `confirmedIncr`, `curedIncr`, `suspectedCountIncr`) VALUES ('20210429', 543, 103595, 5657, 98195, 4857, 466, 0, 33, 22, 13);
    @Select("select datetime as `dateId`,confirmedIncr as `新增确诊`,confirmedCount as `累计确诊`,suspectedCount as `疑似病例`,curedCount as `累计治愈`,deadCount as `累计死亡` from `bigdata`.covid19_1 ")
    List<Map<String, Object>> getCovidTimeData();

    /**查询近两个月的疫情趋势 代替自20200119至今的数据 映射图表*/
    @Select("select date as `dateId` , dead as `累计死亡` , nowConfirm as `累计现存确诊`, heal as `累计治愈`, confirm as `累计确诊`, noInfect as `累计无症状` from `bigdata`.covid19_0 " )
    List<Map<String, Object>> getTwoMonthsData();
    /**
     * 查询全国个省份境外输入的病例数量
     * */
    @Select("select provinceShortName as `name`,confirmedCount as `value` from `bigdata`.covid19_4 where datetime=#{datetime} order by `value` desc limit 10")
    List<Map<String, Object>> getCovidImportData(String datetime);


    /**
    * 根据provinceShortName 和 cityName 来查询该城市的现行确诊人数
     * */
    @Select("select currentConfirmedCount from `bigdata`.covid19_3 where provinceShortName=#{provinceShortName} and cityName=#{cityName}")
    int getCovidCurrentConfirmedCount(String provinceShortName ,String cityName );

    /**
     * 查询并返回用户所要查询的数据
    * */
    @Select("select confirmedCount,currentConfirmedCount,suspectedCount,curedCount,deadCount from `bigdata`.covid19_3 where provinceShortName=#{provinceShortName} and cityName=#{cityName}")
    Map<String,Object> getAreaDetail(String provinceShortName ,String cityName);

    /**
     * 查询近一个月来的新增数据情况
     * */
    @Select("select datetime as `datetime`,confirmedIncr as `新增确诊`,deadIncr as `新增死亡`,curedIncr as `新增治愈`,suspectedCountIncr as `新增疑似` from `bigdata`.covid19_1 limit ${dataIncr},18446744073709551615")
    List<Map<String, Object>> getCovidIncrData(int dataIncr);


    /**
     *查询中国这天的数据作为饼图（最后一条的数据）
     **/
    @Select("select confirm,nowConfirm,suspect,heal,dead from `bigdata`.covid19_0 where id=60")
    Map<String, Object> getChinaData();
}
